package com.four.shop.controller;

import com.four.shop.entity.Pricture;
import com.four.shop.service.PrictureService;
import com.four.shop.util.OssUtils;
import com.guli.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author:wsy
 * @Date: 2021/12/9/15:35
 */
@RestController
@RequestMapping("shop/pricture")
public class PrictureController {

    @Autowired
    private PrictureService prictureService;

    /**
     * 图片上传
     * @param file：文件
     * @return ：返回图片路径
     */
    @PostMapping("/uploadImg")
    public R uploadImg(@RequestBody MultipartFile file) {
        String s = OssUtils.uploadFile(file);
        return R.ok().put("url",s);
    }

    /**
     * 根据id查询图片
     * @param id
     * @return
     */
    @GetMapping("getPictureById/{id}")
    public R getPictureById(@PathVariable("id")Integer id){
        List<Pricture> pricture=prictureService.getPictureById(id);
        return R.ok().put("pricture",pricture);
    }
}
